package com.example.printscreen.printscreen;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.printscreen.printscreen.bean.LoginInfo;
import com.example.printscreen.printscreen.bean.LoginUser;
import com.example.printscreen.printscreen.network.NetworkRequest;
import com.example.printscreen.printscreen.network.TupaiSubscriber;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;


/**
 * 配置页
 */

public class LoginActivity extends RxAppCompatActivity {
    private Context mContext;

    private EditText mCodeEt;
    private EditText mNameEt;
    private EditText mBeginTimeEt;
    private EditText mEndTimeEt;
    private EditText mRoundEt;
    private EditText mAddressEt;
    private Button mLoginBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        mContext = this;

        mCodeEt = (EditText) findViewById(R.id.code_et);
        mNameEt = (EditText) findViewById(R.id.name_et);
        mBeginTimeEt = (EditText) findViewById(R.id.beg_time_et);
        mEndTimeEt = (EditText) findViewById(R.id.end_time_et);
        mRoundEt = (EditText) findViewById(R.id.round_et);
        mAddressEt = (EditText) findViewById(R.id.address_et);
        mLoginBtn = (Button) findViewById(R.id.login_btn);

        mLoginBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String code = mCodeEt.getText().toString();
                String name = mNameEt.getText().toString();
                String begTime = mBeginTimeEt.getText().toString();
                String endTime = mEndTimeEt.getText().toString();
                String roundTime = mRoundEt.getText().toString();
                String addressStr = mAddressEt.getText().toString();
                NetworkRequest.getInstance().login(code, name, begTime, endTime, roundTime, addressStr,
                        new TupaiSubscriber<LoginInfo>(mContext) {
                            @Override
                            protected void requestSuccess(LoginInfo loginInfo) {
                                LoginUser.getInstance().initFromResponse(loginInfo);
                                Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                                startActivity(intent);
                            }

                            @Override
                            protected void requestError(String error) {
                            }
                        });
            }
        });
    }

}
